//
//  DebateTableViewCell.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/2.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "DebateTableViewCell.h"
#import "GXJPrefix.pch"
#import "BrainStormModel.h"


@interface DebateTableViewCell ()
{
    CGFloat _progress1;
    CGFloat _progress2;
}
@property(nonatomic, strong) NSMutableArray * mutableArray;

@end

@implementation DebateTableViewCell
// 重写表格位置，使每一行cell都分隔开
//- (void)setFrame:(CGRect)frame{
//    //    frame.origin.x += 10;
//    frame.origin.y += 5;
//    frame.size.height -= 5;
//    //    frame.size.width -= 20;
//    [super setFrame:frame];
//}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.zhutiDebate];
        [self.contentView addSubview:self.carriedOut];
        
        [self.contentView addSubview:self.theLabel];//商业标签
        [self.contentView addSubview:self.theLabel1];
        [self.contentView addSubview:self.theLabel2];
        
        [self.contentView addSubview:self.timeImage];
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:self.iconLiulang];
        [self.contentView addSubview:self.liulangNum];
        [self.contentView addSubview:self.retangleView];
        [self.retangleView addSubview:self.retangleOne];
        [self.retangleView addSubview:self.retangleTwo];
        [self.retangleView addSubview:self.tetragonal];
        [self.retangleView addSubview:self.antiside];
        [self.retangleView addSubview:self.iconImage];
        [self.retangleView addSubview:self.context];
        [self.retangleView addSubview:self.thumbUp];
        [self.retangleView addSubview:self.thumbUpNum];
        [self.contentView addSubview:self.lineBack];
        [self.retangleView addSubview:self.imagePk];
        [self.retangleOne addSubview:self.literalsPKOne];
        [self.retangleTwo addSubview:self.literalsPKTwo];
        
        
        
        //适配方法
        
    }
    return self;
}

- (void)setUpshipei:(BianlunData_list*)model
{
    
    _zhutiDebate.sd_layout
    .topSpaceToView(self.contentView, kHeightScale(10))
    .leftSpaceToView(self.contentView, kWidthScale(15))
    .rightSpaceToView(self.contentView, kWidthScale(45))
    .autoHeightRatio(0);
    
    _carriedOut.sd_layout
    .topSpaceToView(self.contentView, kHeightScale(10))
    .rightSpaceToView(self.contentView, kWidthScale(15))
    .widthIs(kWidthScale(36))
    .heightIs(kHeightScale(16));
    //商业标签
    _theLabel.sd_layout
    .topSpaceToView(self.zhutiDebate, kHeightScale(8))
    .leftSpaceToView(self.contentView, kWidthScale(15))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(16));
    
    _theLabel1.sd_layout
    .topSpaceToView(self.zhutiDebate, kHeightScale(8))
    .leftSpaceToView(self.theLabel, kWidthScale(5))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(16));
    
    _theLabel2.sd_layout
    .topSpaceToView(self.zhutiDebate, kHeightScale(8))
    .leftSpaceToView(self.theLabel1, kWidthScale(5))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(16));
    
    
    
    
    _timeLabel.sd_layout
    .topSpaceToView(self.zhutiDebate, kHeightScale(8))
    .leftSpaceToView(self.timeImage, kWidthScale(5))
    .autoHeightRatio(0);
    [_timeLabel setSingleLineAutoResizeWithMaxWidth:(40)];
    
    _iconLiulang.sd_layout
    .topSpaceToView(self.zhutiDebate, kHeightScale(11))
    .leftSpaceToView(self.timeLabel, kWidthScale(10))
    .widthIs(kWidthScale(13))
    .heightIs(kHeightScale(8.6));
    
    _liulangNum.sd_layout
    .topEqualToView(self.timeLabel)
    .leftSpaceToView(self.iconLiulang, kWidthScale(5))
    .autoHeightRatio(0);
    [_liulangNum setSingleLineAutoResizeWithMaxWidth:(40)];
    
    _retangleView.sd_layout
    .topSpaceToView(self.theLabel, kHeightScale(8))
    .leftSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0)
    .heightIs(kHeightScale(130));
    
    _tetragonal.sd_layout
    .topSpaceToView(self.retangleView, kHeightScale(5))
    .leftSpaceToView(self.retangleView, kWidthScale(70.5))
    .widthIs(kWidthScale(50))
    .autoHeightRatio(0);
    
    _antiside.sd_layout
    .topSpaceToView(self.retangleView, kHeightScale(5))
    .rightSpaceToView(self.retangleView, kWidthScale(70.5))
    .widthIs(kWidthScale(50))
    .autoHeightRatio(0);
    
    _iconImage.sd_layout
    .topSpaceToView(self.retangleOne, kHeightScale(7))
    .leftSpaceToView(self.retangleView, kWidthScale(15))
    .widthIs(kWidthScale(20))
    .heightIs(kHeightScale(20));
    
    _context.sd_layout
    .centerYEqualToView(self.iconImage)
    .leftSpaceToView(self.iconImage, kWidthScale(3))
    .rightSpaceToView(self.retangleView, kWidthScale(75))
    .heightIs(kHeightScale(14));
    
    _thumbUp.sd_layout
    .topSpaceToView(self.retangleOne, kHeightScale(10))
    .rightSpaceToView(self.retangleView, kWidthScale(44))
    .widthIs(kWidthScale(11))
    .heightIs(kHeightScale(11));
    
    _thumbUpNum.sd_layout
    .topSpaceToView(self.retangleOne, kHeightScale(9))
    .rightSpaceToView(self.retangleView, kWidthScale(10))
    .autoHeightRatio(0);
    [_thumbUpNum setSingleLineAutoResizeWithMaxWidth:(40)];
    
    //cell底部的线条
    _lineBack.sd_layout
    .bottomSpaceToView(self.contentView, 0)
    .leftSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0)
    .heightIs(kHeightScale(5));
    
    //pk图片
    _imagePk.sd_layout
    .topSpaceToView(self.retangleView, kHeightScale(43.5))
    .leftSpaceToView(self.retangleOne, kWidthScale(-2))
    .widthIs(kWidthScale(27))
    .heightIs(kHeightScale(16));
    
    //pk文字
    _literalsPKOne.sd_layout
    .topSpaceToView(self.retangleOne, 0)
    .leftSpaceToView(self.retangleOne, 0)
    .rightSpaceToView(self.retangleOne, 0)
    .bottomSpaceToView(self.retangleOne, 0);
    
    _literalsPKTwo.sd_layout
    .topSpaceToView(self.retangleTwo, 0)
    .leftSpaceToView(self.retangleTwo, 0)
    .rightSpaceToView(self.retangleTwo, 0)
    .bottomSpaceToView(self.retangleTwo, 0);
}
//主题
- (UILabel *)zhutiDebate
{
    if (!_zhutiDebate)
    {
        _zhutiDebate=[[UILabel alloc] init];
        _zhutiDebate.text=@"大学生创业应立足于自身优秀还是市场需求？";
        _zhutiDebate.textColor = [UIColor colorWithHexString:@"#333333"];
        _zhutiDebate.font=[UIFont systemFontOfSize:kWidthScale(14)];
    }
    return _zhutiDebate;
}
//是否进行中
- (UILabel *)carriedOut
{
    if (!_carriedOut)
    {
        _carriedOut=[[UILabel alloc] init];
        _carriedOut.text=@"进行中";
        _carriedOut.textColor=[UIColor colorWithRed:(59.0/255) green:(0.0/255) blue:(204.0/255) alpha:1];
        _carriedOut.textAlignment = NSTextAlignmentCenter;
        _carriedOut.font=[UIFont systemFontOfSize:kWidthScale(10)];
        _carriedOut.layer.borderWidth=0.5;
        _carriedOut.layer.borderColor=[[UIColor colorWithRed:(118.0/255) green:(92.0/255) blue:(211.0/255) alpha:1]CGColor];
        _carriedOut.layer.masksToBounds=YES;
        _carriedOut.layer.cornerRadius=kWidthScale(5);
    }
    return _carriedOut;
}
//标签
- (UILabel *)theLabel
{
    if (!_theLabel)
    {
        _theLabel=[[UILabel alloc] init];
        _theLabel.text=@"商业";
        _theLabel.textColor=[UIColor colorWithHexString:@"109af6"];
        _theLabel.textAlignment = NSTextAlignmentCenter;
        _theLabel.font=[UIFont systemFontOfSize:kWidthScale(9)];
        _theLabel.layer.borderWidth=0.5;
        _theLabel.layer.borderColor=[UIColor colorWithHexString:@"109af6"].CGColor;
        _theLabel.layer.masksToBounds=YES;
        _theLabel.layer.cornerRadius=kWidthScale(5);
    }
    return _theLabel;
}
- (UILabel *)theLabel1
{
    if (!_theLabel1)
    {
        _theLabel1=[[UILabel alloc] init];
        _theLabel1.text=@"商业";
        _theLabel1.textColor=[UIColor colorWithHexString:@"109af6"];
        _theLabel1.textAlignment = NSTextAlignmentCenter;
        _theLabel1.font=[UIFont systemFontOfSize:kWidthScale(9)];
        _theLabel1.layer.borderWidth=0.5;
        _theLabel1.layer.borderColor=[UIColor colorWithHexString:@"109af6"].CGColor;
        _theLabel1.layer.masksToBounds=YES;
        _theLabel1.layer.cornerRadius=kWidthScale(5);
    }
    return _theLabel1;
}
- (UILabel *)theLabel2
{
    if (!_theLabel2)
    {
        _theLabel2=[[UILabel alloc] init];
        _theLabel2.text=@"商业";
        _theLabel2.textColor=[UIColor colorWithHexString:@"109af6"];
        _theLabel2.textAlignment = NSTextAlignmentCenter;
        _theLabel2.font=[UIFont systemFontOfSize:kWidthScale(9)];
        _theLabel2.layer.borderWidth=0.5;
        _theLabel2.layer.borderColor=[UIColor colorWithHexString:@"109af6"].CGColor;
        _theLabel2.layer.masksToBounds=YES;
        _theLabel2.layer.cornerRadius=kWidthScale(5);
    }
    return _theLabel2;
}
//发表时间图标
- (UIImageView *)timeImage
{
    if (!_timeImage)
    {
        _timeImage=[[UIImageView alloc] init];
        _timeImage.image=[UIImage imageNamed:@"time"];
    }
    return _timeImage;
}
//时间
- (UILabel *)timeLabel
{
    if (!_timeLabel)
    {
        _timeLabel=[[UILabel alloc] init];
        _timeLabel.text=@"5:20";
        _timeLabel.textColor=[UIColor colorWithRed:(153.0/255) green:(153.0/255) blue:(153.0/255) alpha:1];
        _timeLabel.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _timeLabel;
}
//浏览图标
- (UIImageView *)iconLiulang
{
    if (!_iconLiulang)
    {
        _iconLiulang=[[UIImageView alloc] init];
        _iconLiulang.image=[UIImage imageNamed:@"liulans"];
    }
    return _iconLiulang;
}
//浏览人数
- (UILabel *)liulangNum
{
    if (!_liulangNum)
    {
        _liulangNum=[[UILabel alloc] init];
        _liulangNum.text=@"100";
        _liulangNum.textColor=[UIColor colorWithRed:(153.0/255) green:(153.0/255) blue:(153.0/255) alpha:1];
        _liulangNum.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _liulangNum;
}
//背景
- (UIView *)retangleView
{
    if (!_retangleView)
    {
        _retangleView=[[UIView alloc] init];
        _retangleView.backgroundColor=[UIColor colorWithRed:(245.0/255) green:(245.0/255) blue:(245.0/255) alpha:1];
    }
    return _retangleView;
}
/** 矩形进度条*/
- (RectangleProgressView *)retangleOne
{
    if (!_retangleOne)
    {
        _retangleOne = [[RectangleProgressView alloc] initWithFrame:CGRectMake(kWidthScale(15), kHeightScale(8.5), kWidthScale(161), kHeightScale(85)) progress:_progress1 standpoint:1 isFinished:NO isWinOrLose:1];
        _retangleOne.backgroundColor=[UIColor colorWithRed:(242.0/255) green:(242.0/255) blue:(242.0/255) alpha:1];
        
    }
    return _retangleOne;
}
- (RectangleProgressView *)retangleTwo
{
    if (!_retangleTwo)
    {
        
        _retangleTwo = [[RectangleProgressView alloc] initWithFrame:CGRectMake(kWidthScale(199), kHeightScale(8.5), kWidthScale(161), kHeightScale(85)) progress:_progress2 standpoint:2 isFinished:NO isWinOrLose:1];
        _retangleTwo.backgroundColor=[UIColor colorWithRed:(242.0/255) green:(242.0/255) blue:(242.0/255) alpha:1];
    }
    return _retangleTwo;
}
//正方
- (UILabel *)tetragonal
{
    if (!_tetragonal)
    {
        _tetragonal=[[UILabel alloc] init];
        _tetragonal.text=@"正方40/50";
        _tetragonal.textColor=[UIColor colorWithRed:(127.0/255) green:(0.0/255) blue:(247.0/255) alpha:1];
        _tetragonal.font=[UIFont systemFontOfSize:kWidthScale(10)];
        _tetragonal.textAlignment = NSTextAlignmentCenter;
    }
    return _tetragonal;
}
//反方
- (UILabel *)antiside
{
    if (!_antiside)
    {
        _antiside=[[UILabel alloc] init];
        _antiside.text=@"反方40/50";
        _antiside.textColor=[UIColor colorWithRed:(0.0/255) green:(88.0/255) blue:(252.0/255) alpha:1];
        _antiside.font=[UIFont systemFontOfSize:kWidthScale(10)];
        _antiside.textAlignment = NSTextAlignmentCenter;
    }
    return _antiside;
}
//头像
- (UIButton *)iconImage
{
    if (!_iconImage)
    {
        _iconImage=[[UIButton alloc] init];
        _iconImage.layer.borderWidth=2;
        _iconImage.layer.masksToBounds=YES;
        _iconImage.layer.borderColor=[[UIColor colorWithRed:(156.0/255) green:(0.0/255) blue:(249.0/255) alpha:1]CGColor];
        _iconImage.layer.cornerRadius=kWidthScale(10);
        [_iconImage setBackgroundImage:[UIImage imageNamed:@"1111"] forState:UIControlStateNormal];
    }
    return _iconImage;
}
//具体内容
- (UILabel *)context
{
    if (!_context)
    {
        _context=[[UILabel alloc] init];
        _context.text=@" : 大学生创业应立足于自身优秀还是市场需求?";
        _context.textColor = [UIColor colorWithHexString:@"#666666"];
        _context.font=[UIFont systemFontOfSize:kWidthScale(12)];
        _context.numberOfLines = 1;
    }
    return _context;
}
//点赞
- (UIButton *)thumbUp
{
    if (!_thumbUp)
    {
        _thumbUp=[[UIButton alloc] init];
        [_thumbUp setBackgroundImage:[UIImage imageNamed:@"zantong"] forState:UIControlStateNormal];
    }
    return _thumbUp;
}
//点赞数量
- (UILabel *)thumbUpNum
{
    if (!_thumbUpNum)
    {
        _thumbUpNum=[[UILabel alloc] init];
        _thumbUpNum.text=@"1000";
        _thumbUpNum.textColor=[UIColor colorWithRed:(153.0/255) green:(153.0/255) blue:(153.0/255) alpha:1];
        _thumbUpNum.font=[UIFont systemFontOfSize:kWidthScale(11)];
    }
    return _thumbUpNum;
}
//cell底部的线条
- (UILabel *)lineBack
{
    if (!_lineBack)
    {
        _lineBack=[[UILabel alloc] init];
        _lineBack.backgroundColor=[UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
        //_lineBack.backgroundColor=[UIColor orangeColor];
    }
    return _lineBack;
}
//pk图片
- (UIImageView *)imagePk
{
    if (!_imagePk)
    {
        _imagePk=[[UIImageView alloc] init];
        _imagePk.image=[UIImage imageNamed:@"pk-12"];
        _imagePk.backgroundColor=[UIColor colorWithRed:(242.0/255) green:(242.0/255) blue:(242.0/255) alpha:1];
    }
    return _imagePk;
}
//pk文字
- (UILabel *)literalsPKOne
{
    if (!_literalsPKOne)
    {
        _literalsPKOne=[[KQlable alloc] init];
        _literalsPKOne.text=@"啊啊啊啊。啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊撒旦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊。\n";
        _literalsPKOne.font=[UIFont systemFontOfSize:kWidthScale(11)];
        //_literalsPKOne.backgroundColor=[UIColor orangeColor];
        _literalsPKOne.numberOfLines=0;
        _literalsPKOne.textAlignment= NSTextAlignmentCenter;
        _literalsPKOne.textColor=[UIColor colorWithRed:(102.0/255) green:(102.0/255) blue:(102.0/255) alpha:1];
        [UILabel changeLineSpaceForLabel:_literalsPKOne WithSpace:5.0f];
    }
    return _literalsPKOne;
}
- (UILabel *)literalsPKTwo
{
    if (!_literalsPKTwo)
    {
        _literalsPKTwo=[[KQlable alloc] init];
        _literalsPKTwo.text=@"啊啊啊啊。啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊撒旦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊。\n";
        _literalsPKTwo.font=[UIFont systemFontOfSize:kWidthScale(11)];
        //_literalsPKTwo.backgroundColor=[UIColor orangeColor];
        _literalsPKTwo.numberOfLines=0;
        _literalsPKTwo.textAlignment=NSTextAlignmentCenter;
        _literalsPKTwo.textColor=[UIColor colorWithRed:(102.0/255) green:(102.0/255) blue:(102.0/255) alpha:1];
        [UILabel changeLineSpaceForLabel:_literalsPKTwo WithSpace:5.0f];
    }
    return _literalsPKTwo;
}
//数据赋值
- (void)setModel:(BianlunData_list *)model
{
    
    _zhutiDebate.text=model.title;
    self.theLabel .hidden = NO;
    self.theLabel1.hidden = NO;
    self.theLabel2.hidden = NO;
    if (model.industryid.count == 3) {
        self.theLabel.text = model.industryid[0];
        self.theLabel1.text = model.industryid[1];
        self.theLabel2.text = model.industryid[2];
        _timeImage.sd_layout
        .topSpaceToView(self.contentView, kHeightScale(36))
        .leftSpaceToView(self.contentView, kWidthScale(140))
        .widthIs(kWidthScale(13))
        .heightIs(kHeightScale(13));
    }else if (model.industryid.count == 2){
        self.theLabel.text = model.industryid[0];
        self.theLabel1.text = model.industryid[1];
        self.theLabel2.hidden = YES;
        _timeImage.sd_layout
        .topSpaceToView(self.contentView, kHeightScale(36))
        .leftSpaceToView(self.contentView, kWidthScale(105))
        .widthIs(kWidthScale(13))
        .heightIs(kHeightScale(13));
    }else{
        self.theLabel.text = model.industryid[0];
        self.theLabel1.hidden = YES;
        self.theLabel2.hidden = YES;
        _timeImage.sd_layout
        .topSpaceToView(self.contentView, kHeightScale(36))
        .leftSpaceToView(self.contentView, kWidthScale(60))
        .widthIs(kWidthScale(13))
        .heightIs(kHeightScale(13));
    }
   
    NSString *timeCurrent = [self timeWithTimeIntervalString:[model.create_date stringValue]];
    _timeLabel.text = timeCurrent;
    [self setUpshipei:model];
    BOOL result = [self StringIsNullOrEmpty:[model.viewnum stringValue]];
    if (result) {
        _liulangNum.text = @"0";
    }else{
        _liulangNum.text = [model.viewnum stringValue];
    }
    _literalsPKOne.text = model.option1;
    _literalsPKTwo.text = model.option2;
    _tetragonal.text=[NSString stringWithFormat:@"正方%@/50",[model.option1num stringValue]];
    _antiside.text=[NSString stringWithFormat:@"反方%@/50",[model.option2num stringValue]];
    
    _progress1 = [model.option1num floatValue]/100;
    _progress2 = [model.option2num floatValue]/100;
    //_progress1 = [_progress1 substringToIndex:7];
    NSLog(@"%f",_progress1);
//    _retangleOne.progress = fffloat;
//    _retangleTwo.progress = fffloat2;
    
    
//    BOOL dianzan = [self StringIsNullOrEmpty:[model.viewnum stringValue]];
//    if (dianzan) {
//        _liulangNum.text = @"0";
//    }else{
//        _liulangNum.text = [model.viewnum stringValue];
//    }
}

- (void)setList_comment:(BianlunData_list_comment *)list_comment
{
    
    
    if (![list_comment.head_img isEqualToString:@""]) {
        [_iconImage sd_setBackgroundImageWithURL:[NSURL URLWithString:list_comment.head_img] forState:0 placeholderImage:[UIImage imageNamed:@""]];
        _context.text = [NSString stringWithFormat:@" ：%@",list_comment.content];
        _thumbUpNum.text=[NSString stringWithFormat:@"%@",[list_comment.agree stringValue]];
        
        self.iconImage.hidden = NO;
        self.context.hidden = NO;
        self.thumbUp.hidden = NO;
        self.thumbUpNum.hidden = NO;
        
        _retangleView.sd_layout
        .topSpaceToView(self.theLabel, kHeightScale(8))
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(kHeightScale(125.5));
    }else if ([list_comment.head_img isEqualToString:@""])
    {
        self.iconImage.hidden = YES;
        self.context.hidden = YES;
        self.thumbUp.hidden = YES;
        self.thumbUpNum.hidden = YES;
        
        _retangleView.sd_layout
        .topSpaceToView(self.theLabel, kHeightScale(8))
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(kHeightScale(98.5));
    }
    
    
}
// 若后台返回值为NULL或者<NULL>时，返回yes
- (BOOL)StringIsNullOrEmpty:(NSString *)str
{
    return (str == nil || [str isKindOfClass:[NSNull class]] || str.length == 0);
}
// 时间戳转换
- (NSString *)timeWithTimeIntervalString:(NSString *)timeString
{
    NSTimeInterval interval    =[timeString doubleValue] / 1000.0;
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm"]; // yyyy-MM-dd HH:mm:ss
    NSString *dateString       = [formatter stringFromDate: date];
    
    return dateString;
}


@end
